<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <title>
        Git基本功能介绍 - Pure theme for Hugo
      </title>
    <head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport"
    content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  
  <meta name="theme-color" content="#000000" />
  
  <meta http-equiv="window-target" content="_top" />
  
  
  <meta name="description" content="本文介绍git的基本功能" />
  <meta name="generator" content="Hugo 0.68.0 with theme pure" />
  <title>Git基本功能介绍 - Pure theme for Hugo</title>
  
  
  <link rel="stylesheet" href="https://i-lovezxl.gitee.io/css/style.min.7dc20efbc53647d41aa9ddea0c48e59300223d084e66ea0cbe7c30bd88903acc.css">
  
  <link rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/9.15.10/styles/monokai.min.css" async>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.css" async>
  <meta property="og:title" content="Git基本功能介绍" />
<meta property="og:description" content="本文介绍git的基本功能" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://i-lovezxl.gitee.io/posts/2020/03/git-base-introduce/" />
<meta property="article:published_time" content="2020-03-22T14:02:49+08:00" />
<meta property="article:modified_time" content="2020-03-22T14:02:49+08:00" />
<meta itemprop="name" content="Git基本功能介绍">
<meta itemprop="description" content="本文介绍git的基本功能">
<meta itemprop="datePublished" content="2020-03-22T14:02:49&#43;08:00" />
<meta itemprop="dateModified" content="2020-03-22T14:02:49&#43;08:00" />
<meta itemprop="wordCount" content="1526">



<meta itemprop="keywords" content="" /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Git基本功能介绍"/>
<meta name="twitter:description" content="本文介绍git的基本功能"/>

  <!--[if lte IE 9]>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
    <![endif]-->

  <!--[if lt IE 9]>
      <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
      <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
    <![endif]-->

</head>
  </head>

  
  

  <body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage"><header class="header" itemscope itemtype="http://schema.org/WPHeader">
    <div class="slimContent">
      <div class="navbar-header">
        <div class="profile-block text-center">
          <a id="avatar" href="https://gitee.com/i-lovezxl/" target="_blank">
            <img class="img-circle img-rotate" src="https://i-lovezxl.gitee.io/avatar.png" width="200" height="200">
          </a>
          <h2 id="name" class="hidden-xs hidden-sm">玄汯</h2>
          <h3 id="title" class="hidden-xs hidden-sm hidden-md">硬中带软工程师</h3>
          <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i>北京, 中国</small>
        </div><div class="search" id="search-form-wrap">
    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i
                        class="icon icon-search"></i></button>
            </span>
        </div>
        <div class="ins-search">
            <div class="ins-search-mask"></div>
            <div class="ins-search-container">
                <div class="ins-input-wrapper">
                    <input type="text" class="ins-search-input" placeholder="想要查找什么..."
                        x-webkit-speech />
                    <button type="button" class="close ins-close ins-selectable" data-dismiss="modal"
                        aria-label="Close"><span aria-hidden="true">×</span></button>
                </div>
                <div class="ins-section-wrapper">
                    <div class="ins-section-container"></div>
                </div>
            </div>
        </div>
    </form>
</div>
        <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
      </div>
      <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
        <ul class="nav navbar-nav main-nav">
            <li class="menu-item menu-item-home">
                <a href="/">
                    <i class="icon icon-home-fill"></i>
                  <span class="menu-title">Home</span>
                </a>
            </li>
            <li class="menu-item menu-item-archives">
                <a href="/posts/">
                    <i class="icon icon-archives-fill"></i>
                  <span class="menu-title">Archives</span>
                </a>
            </li>
            <li class="menu-item menu-item-categories">
                <a href="/categories/">
                    <i class="icon icon-folder"></i>
                  <span class="menu-title">Categories</span>
                </a>
            </li>
            <li class="menu-item menu-item-tags">
                <a href="/tags/">
                    <i class="icon icon-tags"></i>
                  <span class="menu-title">Tags</span>
                </a>
            </li>
            <li class="menu-item menu-item-about">
                <a href="/about/">
                    <i class="icon icon-cup-fill"></i>
                  <span class="menu-title">About</span>
                </a>
            </li>
        </ul>
      </nav>
    </div>
  </header>

<aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content"><p>enjoy~</p>
            </div>
        </div>
    </div>
</div>

      <div class="widget">
    <h3 class="widget-title"> 分类</h3>
    <div class="widget-body">
        <ul class="category-list">
            <li class="category-list-item"><a href="https://i-lovezxl.gitee.io/categories/git/" class="category-list-link">git</a><span class="category-list-count">2</span></li>
            <li class="category-list-item"><a href="https://i-lovezxl.gitee.io/categories/hugo/" class="category-list-link">hugo</a><span class="category-list-count">2</span></li>
            <li class="category-list-item"><a href="https://i-lovezxl.gitee.io/categories/linux/" class="category-list-link">linux</a><span class="category-list-count">3</span></li>
            <li class="category-list-item"><a href="https://i-lovezxl.gitee.io/categories/vps/" class="category-list-link">vps</a><span class="category-list-count">2</span></li>
        </ul>
    </div>
</div>
      <div class="widget">
    <h3 class="widget-title"> 标签</h3>
    <div class="widget-body">
        <ul class="tag-list">
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/gitee/" class="tag-list-link">gitee</a><span
                    class="tag-list-count">2</span></li>
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/hugo/" class="tag-list-link">hugo</a><span
                    class="tag-list-count">2</span></li>
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/index/" class="tag-list-link">index</a><span
                    class="tag-list-count">1</span></li>
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/joystick/" class="tag-list-link">joystick</a><span
                    class="tag-list-count">1</span></li>
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/stm32/" class="tag-list-link">stm32</a><span
                    class="tag-list-count">2</span></li>
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/usage/" class="tag-list-link">usage</a><span
                    class="tag-list-count">3</span></li>
            
            
            <li class="tag-list-item"><a href="https://i-lovezxl.gitee.io/tags/vps/" class="tag-list-link">vps</a><span
                    class="tag-list-count">1</span></li>
            
        </ul>

    </div>
</div>
      
<div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
        <ul class="recent-post-list list-unstyled no-thumbnail">
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://i-lovezxl.gitee.io/posts/2020/08/win10-vscode-docker-compile-env/" class="title">Win10系统下搭建Vscode&#43;Docker嵌入式编译调试环境</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-08-25 22:58:26 &#43;0800 CST" itemprop="datePublished">2020-08-25</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://i-lovezxl.gitee.io/posts/2020/07/stm32-startup-process/" class="title">STM32启动流程分析</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-07-05 16:36:41 &#43;0800 CST" itemprop="datePublished">2020-07-05</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://i-lovezxl.gitee.io/posts/2020/06/vim-plugin-vundle/" class="title">VIM插件环境搭建</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-24 19:16:27 &#43;0800 CST" itemprop="datePublished">2020-06-24</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://i-lovezxl.gitee.io/posts/2020/06/nextcloud-install-on-openmediavault/" class="title">入坑openmediavault nextcloud</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-06 14:38:12 &#43;0800 CST" itemprop="datePublished">2020-06-06</time>
                    </p>
                </div>
            </li>
            <li>
                <div class="item-inner">
                    <p class="item-title">
                        <a href="https://i-lovezxl.gitee.io/posts/2020/06/stm32-hard-fault-diagnosis/" class="title">STM32 HardFault诊断方法</a>
                    </p>
                    <p class="item-date">
                        <time datetime="2020-06-03 10:30:07 &#43;0800 CST" itemprop="datePublished">2020-06-03</time>
                    </p>
                </div>
            </li>
        </ul>
    </div>
</div>
  </div>
</aside>

    
    
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <h4 class="toc-title">文章目录</h4>
    <nav id="toc" class="js-toc toc">

    </nav>
  </div>
</aside>
<main class="main" role="main"><div class="content">
  <article id="-git-base-introduce" class="article article-type-" itemscope
    itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      <h1 itemprop="name">
  <a
    class="article-title"
    href="/posts/2020/03/git-base-introduce/"
    >Git基本功能介绍</a
  >
</h1>

      <div class="article-meta">
        
<span class="article-date">
  <i class="icon icon-calendar-check"></i>&nbsp;
<a href="https://i-lovezxl.gitee.io/posts/2020/03/git-base-introduce/" class="article-date">
  <time datetime="2020-03-22 14:02:49 &#43;0800 CST" itemprop="datePublished">2020-03-22</time>
</a>
</span>
<span class="article-category">
  <i class="icon icon-folder"></i>&nbsp;
  <a class="article-category-link" href="/categories/git/"> git </a>
</span>

        <span class="post-comment"><i class="icon icon-comment"></i>&nbsp;<a href="/posts/2020/03/git-base-introduce/#comments"
            class="article-comment-link">评论</a></span>
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计: 1526字</span>
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长: 4分 </span>
      </div>
    </div>
    <div class="article-entry marked-body js-toc-content" itemprop="articleBody">
      <p>本文介绍git的基本功能</p>
<h3 id="clone">clone</h3>
<p>克隆，顾名思义就是完全复制出一个一模一样的仓库来，把远端的仓库信息拿到本地。</p>
<h3 id="fetch">fetch</h3>
<p>获取，获取什么呢？其实就是和之前克隆的仓库或者是新增的远端仓库进行同步，如果远端仓库有新的提交，则更新本地记录的远端仓库信息，但并不影响工作区内的任何文件。</p>
<h3 id="merge">merge</h3>
<p>合并，就是让两个不同的分支进行历史及代码的合并，把另一个分支合并到当前分支，会改变工作区的文件。</p>
<h3 id="pull">pull</h3>
<p>pull = fetch + merge，先获取远端分支信息，再将其合并到当前分支，当然也就是改变工作的文件了，这个操作也是我们经常更新代码时使用，但它与SVN的update还是不太一样的，也是经常被误解的一个操作，理解pull的工作原理才能更好的使用它。</p>
<h3 id="checkout">checkout</h3>
<p>检出，就是把文件从版本库中提取出来，这个功能还是很强大的，可以做很多事情，如：切换分支、创建并切换到新的分支、恢复工作区有变化的文件等。</p>
<h3 id="add">add</h3>
<p>添加，这个功能就是将有变化（修改、新增、删除）的文件添加到暂存区，这也是git和svn最大的区别——多了一个暂存区的概念，它是一个中间状态，只有被提交到的暂存区的变更才能最终被提交到本地的版本库里。</p>
<h3 id="commit">commit</h3>
<p>提交，上面已经提到了，会将暂存区中的内存提交到本地的版本库中；图形界面TortoiseGit里的commit实际上是add + commit，省略了add的步骤，如果用命令行的就可以更好的理解暂存区的概念了。commit时会通过SHA-1的算法算出一个40位的16进制数字来标识一次提交，svn的话只是一个递增的序号，前段时间在网上看到，linus好像是想改用其它算法了，不知道真假。</p>
<h3 id="push">push</h3>
<p>push和pull是类似的，都是与远端库进行同步，只是方向不同而已。push(推)自然是将本地提交的commit推送到远端了。</p>
<h3 id="clean">clean</h3>
<p>清理，svn中的clean是将清理版本库的状态，当你做某个操作时意外中止了，再做其它操作时就可能会让你clean一下；而git的功能却完全不同，它是将本地没用的文件清理掉，没用的文件主要是不受版本库控制的文件，这一点也是经常被弄混。</p>
<h3 id="revert">revert</h3>
<p>恢复，这个功能svn和git也是不同的，svn和TortoiseGit的revert是将本地未提交的变更恢复成与版本库的一致，而git是使用checkout与实现的这一功能。那么，git revert是做什么的呢？其实它也是恢复，只不过是恢复之前的某一次提交，即将之前的某一次的修改再给改回去，并生成一个新的提交。</p>
<h3 id="blame">blame</h3>
<p>这个功能就和svn是一样的了，查看文件每一行代码对应的最后一次commit</p>
<h3 id="cherry-pick">cherry-pick</h3>
<p>将commit从一个分支提交到另一个分支，会重新生成一个新的SHA值，但是log、提交日期、提交人等信息还是一样的。cherry-pick多个commit的时候，要注意顺序，和之前commit的顺序要一致，否则可能会出现冲突。</p>
<h3 id="rebase">rebase</h3>
<p>衍合，可以把在一个分支里提交的改变移到另一个分支里重放一遍。它的原理是回到两个分支最近的共同祖先，根据当前分支（也就是要进行衍合的分支 experiment）后续的历次提交对象，生成一系列文件补丁，然后以基底分支（也就是主干分支 master）最后一个提交对象为新的出发点，逐个应用之前准备好的补丁文件，最后会生成一个新的合并提交对象，从而改写 experiment 的提交历史，使它成为 master 分支的直接下游 。</p>
<h3 id="reset">reset</h3>
<p>在提交层面上，reset将一个分支的末端指向另一个提交。这可以将当前分支指向之前的提交，用来移除当前分支的一些提交。</p>
<h3 id="stash">stash</h3>
<p>隐藏，当你正在改一个bug改到一半的时候，又有一个紧急bug修改，这时怎么办呢？之前改的不要了？不划算啊！这时就用到stash了，将当前修改到的文件先隐藏起来，然后再切换到别的分支修改紧急bug，修改完之后再把stash的内容pop出来，就可以继续修改了。</p>

    </div>
    <div class="article-footer">
<blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接: </strong>
      <a href="https://i-lovezxl.gitee.io/posts/2020/03/git-base-introduce/" title="Git基本功能介绍" target="_blank" rel="external">https://i-lovezxl.gitee.io/posts/2020/03/git-base-introduce/</a>
    </li>
    <li class="post-copyright-license">
      <strong>License：</strong><a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN</a>
    </li>
  </ul>
</blockquote>

<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://gitee.com/i-lovezxl/" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="https://i-lovezxl.gitee.io/avatar.png" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://gitee.com/i-lovezxl/" target="_blank"><span class="text-dark">玄汯</span><small class="ml-1x">硬中带软工程师</small></a></h3>
        <div>上善若水，水善利万物而不争</div>
      </div>
    </figure>
  </div>
</div>
    </div>
  </article>
<section id="comments">
</section>

</div><nav class="bar bar-footer clearfix" data-stick-bottom>
    <div class="bar-inner">
        <ul class="pager pull-left">
            <li class="prev">
                <a href="https://i-lovezxl.gitee.io/posts/2020/03/what-is-git/" title="What Is Git"><i
                        class="icon icon-angle-left"
                        aria-hidden="true"></i><span>&nbsp;&nbsp;下一篇</span></a>
            </li>
            <li class="next">
                <a href="https://i-lovezxl.gitee.io/posts/2020/03/linux-show-git-branch-name/"
                    title="Linux终端显示git分支名称"><span>上一篇&nbsp;&nbsp;</span><i
                        class="icon icon-angle-right" aria-hidden="true"></i></a>
            </li>
            
            <li class="toggle-toc">
                <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false"
                    title="文章目录" role="button">
                    <span>[&nbsp;</span><span>文章目录</span>
                    <i class="text-collapsed icon icon-anchor"></i>
                    <i class="text-in icon icon-close"></i>
                    <span>]</span>
                </a>
            </li>
        </ul>
        <div class="bar-right">
            <div class="share-component" data-sites="weibo,qq,wechat"
                data-mobile-sites="weibo,qq,qzone"></div>
        </div>
    </div>
</nav>

</main><footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
<ul class="social-links">
    <li><a href="https://gitee.com/i-lovezxl/" target="_blank" title="gitee" data-toggle=tooltip data-placement=top >
            <i class="icon icon-gitee"></i></a></li>
</ul>
  <div class="copyright">
    &copy;2010  -
    2020
    <div class="publishby">
        Theme by <a href="https://github.com/xiaoheiAh" target="_blank"> xiaoheiAh </a>base on<a href="https://github.com/xiaoheiAh/hugo-theme-pure" target="_blank"> pure</a>.
    </div>
  </div>
</footer>

<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_SVG"></script>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
            showMathMenu: false, //disables context menu
            tex2jax: {
            inlineMath: [ ['$','$'], ['\\(','\\)'] ]
           }
    });
</script>


<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
<script>
    window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/highlight.min.js"></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/python.min.js" defer></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/javascript.min.js" defer></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/shell.min.js" defer></script>
<script type="text/javascript" src="https://cdn.staticfile.org/highlight.js/9.15.10/languages/cpp.min.js" defer></script><script>
    hljs.configure({
        tabReplace: '    ', 
        classPrefix: ''     
        
    })
    hljs.initHighlightingOnLoad();
</script>
<script src="https://i-lovezxl.gitee.io/js/application.min.bdeb64b910570b6c41badc6a05b7afb0c8ad9efd8525de3c7257d59e786326a3.js"></script>
<script src="https://i-lovezxl.gitee.io/js/plugin.min.51ff8c7317566f82259170fa36e09c4493adc9b9378b427a01ad3f017ebac7dd.js"></script>

<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: '文章',
                PAGES: '页面',
                CATEGORIES: '分类',
                TAGS: '标签',
                UNTITLED: '(未命名)',
            },
            ROOT_URL: 'https:\/\/i-lovezxl.gitee.io\/',
            CONTENT_URL: 'https:\/\/i-lovezxl.gitee.io\/\/searchindex.json ',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script type="text/javascript" src="https://i-lovezxl.gitee.io/js/insight.min.a343cd9a5a7698336b28ef3a7c16a3a1b1d2d5fb17dc8ed04022bbe08cc5459073a15bdafa3a8a58cdd56080784bdd69fa70b1ae8597565c799c57ed00f0e120.js" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tocbot/4.4.2/tocbot.min.js"></script>
<script>
    tocbot.init({
        
        tocSelector: '.js-toc',
        
        contentSelector: '.js-toc-content',
        
        headingSelector: 'h1, h2, h3',
        
        hasInnerContainers: true,
    });
</script>


  </body>
</html>
